$('#container').css('height',($(window).height-60)+'px');
//var categories = [{name:'恋爱情感',image:'img/icons/type7.png'},{name:'恋爱情感',image:'img/icons/type7.png'}];
function toQuickAskDetailN(id) {
    server.loadindex('page/quickask/quickaskdetail/quickaskdetail','id='+id,false);

};
function quickAskType(typeid) {
    server.loadindex('page/quickask/typelist/typelist','typeid='+typeid);
}
$(function () {
    //判断是否有新消息
    var newsflag = server.getCache("newsflag");
    if(newsflag==1){
        $("#newsflag").css("display","block");
    }

    var types;
    //判断有没有标题的修饰图片
    var strTitleImage;
    server.req('wechat/quicktestype/list',{},function (res) {
        // console.log(res);
        if(res.code==0){
            // server.loadData(".CTop",res);
            res.data1=res.data;
            console.log(res)
            server.loadData(".container",res);

            types = res.data;
            types.forEach(function (item,index) {
                if(item.titleImage){
                    strTitleImage = '<img style="height:18px;margin-bottom:-3px;" src="'+item.titleImage+'" />'
                    $("#timage"+item.id).html(strTitleImage);
                }else{
                    console.log("title image is null")
                }
                server.req('wechat/quicktest/list',{typeId:item.id,page:1,limit:10},function (e) {
                    console.log("articles:");
                    console.log(e);
                    
                    var asksHtml="<div style='width:100%;height: 40px;line-height:40px;'><label style='font-size:14px;margin-left:20px'>当前分类没有内容</label></div>";
                    
                    if(e.code==0){
                        e.size=e.data&&e.data.length>0;
                        if(e.data.length>0){
                            asksHtml="";
                        }
                        e.data.forEach(function (ask,askindex) {
                            asksHtml = asksHtml+'<div class="bblock-body-item" onclick="toQuickAskDetailN(&quot;'+ask.id+'&quot;)">\n' +
                                '                            <div class="bblock-body-item-image">\n' +
                                '                                <img src="'+ask.image+'" />\n' +
                                '                            </div>\n' +
                                '                            <div class="bblock-body-item-detail">\n' +
                                '                                <div class="bblock-body-item-detail-title">\n' +
                                '                                    <label data-item="title">'+ask.title+'</label>\n' +
                                '                                </div>\n' +
                                '                                <div class="bblock-body-item-detail-subtitle">\n' +
                                '                                    <label data-item="subtitle">'+ask.subtitle+'</label>\n' +
                                '                                </div>\n' +
                                '                                <div class="bblock-body-item-detail-numbers">\n' +
                                '\n' +
                                '                                    <label style="float: left"><img src="img/quick/22.png" style=" width:16px;height: 12px;"/><span data-item="openTimes">'+ask.openTimes+'</span> 浏览</label><label style="float: right"><img src="img/quick/20.png" style=" width:13px;height: 12px;"/><span data-item="testPeoplenum">'+ask.testPeoplenum+'</span> 提问</label><label style="float: right"><img src="img/quick/20.png" style=" width:13px;height: 12px;"/><span data-item="evalPeoplenum">'+ask.evalPeoplenum+'</span> 评论</label>\n' +
                                '\n' +
                                '                                </div>\n' +
                                '                            </div>\n' +
                                '                        </div>'
                        });

                        $(".CBblock-body"+item.id).html(asksHtml);
                        //server.loadData(".CBblock-body"+item.id,e);
                    }

                })
            }) //结束某一分类的问题列表

        } //结束分类
    })
})